(function(){
	var AjaxCrud = QualityCheck.AjaxCRUD;
	var serverUrl = QualityCheck.GPUD.ServiceConfig;
	var dataCache = [];
	var pageSize = 10;
	var currentPage = 1;
	$(function(){
		var usercode = $("#user-name",parent.parent.document).attr("code");
		var userkey = $("#user-name",parent.parent.document).attr("key");
		var usertype = $("#user-name",parent.parent.document).attr("usertype");
		keyCheck(usercode,usertype,userkey,function(){
			initSmPages();
			window.onresize = function () {
				initSmPages();
			};
			pagebtns();
			initExam(1,pageSize);
		});
	});
	function initExam(currentpage,pagesize){
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		var studentcode = $(".students-choice-select",parent.document).attr("studentcode");
		var starttime = strToDate($("#start-time").val() + "-01 00:00:00")/1000;
		var endtime = strToDate($("#end-time").val() + "-01 00:00:00")/1000;
		var obj = {
				schoolcode:schoolcode,
				studentcode:studentcode,
				currentpage:currentpage,
				pagesize:pagesize,
				
		};
		if($("#start-time").val() != "" && $("#end-time").val() != ""){
			if(endtime <= starttime){
				$("#judge-time").text("结束时间要大于起始时间");
				$("#judge-time").show();
				return false;
			}
		}
		if($("#start-time").val() != "" && $("#end-time").val() != ""){
			obj.starttime = starttime;
			obj.endtime = endtime;
			$("#judge-time").hide();
		}else if($("#start-time").val() == "" && $("#end-time").val() == ""){
			$("#judge-time").hide();
		}else{
			$("#judge-time").text("请把时间填充完整");
			$("#judge-time").show();
			return false;
		}
		var data = {
				cmd:"getParentChildrenExamList",
				model:"bigexam",
				userKey:userKey,
				data:obj,
				remark:"",
		};
		processBegin("数据加载中······");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			var content = "";
			var pagecontent = "<div class=\"pages-btn-next\">&gt;&gt;</div>";
			if(res.result == 1 && res.data != undefined && res.data != ""){
				var data = res.data;
				if(data.length > 0){
					var total = res.data.length;
					totalSize = Math.ceil(total/pagesize);
					if(totalSize <= 5 && totalSize >0){
						for(var i = totalSize-1 ; i >= 0; i--){
							if(i == currentpage-1){
								pagecontent += "<div class=\"pages-btn page-btn-select\">"+(i + 1)+"</div>"; 
							}else{
								pagecontent += "<div class=\"pages-btn\">"+(i + 1)+"</div>"; 
							}
						}
					}else if(totalSize == 0){
						pagecontent += "<div class=\"pages-btn\">1</div>";
					}else if(totalSize > 5){
						var lastp = (now*5)+5;
						if(lastp > totalSize){
							lastp = totalSize;
						}
						for(var i = lastp-1 ; i >= (now*5); i--){
							if(i == currentpage-1){
								pagecontent += "<div class=\"pages-btn page-btn-select\">"+(i + 1)+"</div>"; 
							}else{
								pagecontent += "<div class=\"pages-btn\">"+(i + 1)+"</div>"; 
							}
						}
					}
					pagecontent += "<div class=\"pages-btn-last\">&lt;&lt;</div>";
//					$("#student-page").empty();
//					$("#student-page").append(pagecontent);
					
					$(".pages-btn").unbind("click");
					$(".pages-btn").click(function(){
						$(".pages-btn").removeClass("page-btn-select");
						$(this).addClass("page-btn-select");
						currentPage = parseInt($(this).text());
						initExam(currentPage,pageSize);
					});
					
					$(".pages-btn-last").unbind("click");
					$(".pages-btn-last").click(function(){
						if(totalSize <= 5 && totalSize >0){
							return false;
						}else if(totalSize == 0){
							return false;
						}else if(totalSize > 5){
							if(now > 0){
								now --;
								initExam((now*5+1),pageSize);
							}else{
								return false;
							}
						}
					});
					
					$(".pages-btn-next").unbind("click");
					$(".pages-btn-next").click(function(){
						if(totalSize <= 5 && totalSize >0){
							return false;
						}else if(totalSize == 0){
							return false;
						}else if(totalSize > 5){
							if(totalSize%5 == 0){
								if((now+1) < totalSize/5){
									now ++;
									initExam((now*5+1),pageSize);
								}else{
									return false;
								}
							}else{
								if((now+1) <= (totalSize-totalSize%5)/5){
									now ++;
									initExam((now*5+1),pageSize);
								}else{
									return false;
								}
							}
						}
					});
					if(data.length > 0){
						dataCache = [];
						for(var i = 0; i < data.length; i++){
							for(var key in data[i]){
								if(data[i][key] == null || data[i][key] == "null" || data[i][key] == undefined){
									data[i][key] = "";
								}
							}
							content += "<div class=\"table-trs\">" +
								"<div class=\"tables-left\" style='margin-left:15px;width:320px;'>" +
									"<div class=\"table-name\" style='width:320px;' examcode=\""+data[i].examcode+"\" grades = \""+data[i].grades+"\" examname=\""+data[i].examname+"\" title='"+data[i].examname+"'><a href='javascript:void(0)' class='into-exam-detail'>"+substr(data[i].examname,15)+ "</a></div>" +
									"<div class=\"table-code\" style='width:320px;' title='"+data[i].describe+"'>"+substr(data[i].describe,20)+"</div>" +
								"</div>" +
								"<div class=\"tables-right\">" +
									"<div class=\"table-address\">创建于:"+getFormatDateByLong(parseInt(data[i].createtime)*1000,"yyyy-MM-dd hh:mm")+"</div>" +
									"<div class=\"table-oprate\">" +
										"<div class=\"table-detail\" style=\"margin-left:70px\" dataindex = \""+i+"\" grades = \""+data[i].grades+"\" examcode=\""+data[i].examcode+"\" examname=\""+data[i].examname+"\" title=\"详情\"></div>" +
										"<div class=\"table-ranking\" style=\"margin-left:15px\" dataindex = \""+i+"\" grades = \""+data[i].grades+"\" examcode=\""+data[i].examcode+"\" examname=\""+data[i].examname+"\" title=\"排名\"></div>" +
									"</div>" +
								"</div>" +
							"</div>";
							dataCache.push(data[i]);
						}
						$("#exam-data-show").empty();
						$("#exam-data-show").append(content);
						processEnd("加载成功");
						
						$(".table-trs").unbind("hover");
						$(".table-trs").hover(function(){
							$(this).find(".table-oprate").show();
						},function(){
							$(".table-oprate").hide();
						});
						//点击考试名称进入详情（总榜）
						$(".table-name").unbind("click");
						$(".table-name").click(function(){
							var examcode = $(this).attr("examcode");
							var examname = $(this).attr("examname");
							var grades = $(this).attr("grades");
							$("#detail-form-show").contents().find(".table-title").text(examname + "总榜");
							$("#detail-form-show").show();
							$("#right-tables").hide();
							$("#detail-form-show").contents().find("#back-to-table").unbind("click");
							$("#detail-form-show").contents().find("#back-to-table").click(function(){
								$("#detail-form-show").hide();
								$("#right-tables").show();
								$("#start-time").show();
								$("#end-time").show();
								$("#exam-search-btn").show();
							});
							$("#start-time").hide();
							$("#end-time").hide();
							$("#exam-search-btn").hide();
							getExamDetail(examname,examcode,grades);
						});
						//点击详情，进入考试详情（总榜）
						$(".table-detail").unbind("click");
						$(".table-detail").click(function(){
							var examcode = $(this).attr("examcode");
							var examname = $(this).attr("examname");
							var grades = $(this).attr("grades");
							$("#detail-form-show").contents().find(".table-title").text(examname + "总榜");
							$("#detail-form-show").show();
							$("#right-tables").hide();
							$("#detail-form-show").contents().find("#back-to-table").unbind("click");
							$("#detail-form-show").contents().find("#back-to-table").click(function(){
								$("#detail-form-show").hide();
								$("#right-tables").show();
								$("#start-time").show();
								$("#end-time").show();
								$("#exam-search-btn").show();
							});
							$("#start-time").hide();
							$("#end-time").hide();
							$("#exam-search-btn").hide();
							getExamDetail(examname,examcode,grades);
						});
						//总成绩排名
						$(".table-ranking").unbind("click");
						$(".table-ranking").click(function(){
//							var index = parseInt($(this).attr("dataindex"));
							var examname = $(this).attr("examname");
							var examcode = $(this).attr("examcode");
							var grades = $(this).attr("grades");
							$("#rank-form-show").contents().find(".table-title").text(examname + "成绩单");
							$("#rank-form-show").show();
							$("#right-tables").hide();
							$("#rank-form-show").contents().find("input").removeAttr("disabled");
							$("#rank-form-show").contents().find("input").css("background-color","#fff");
							$("#rank-form-show").contents().find("#back-to-table").unbind("click");
							$("#rank-form-show").contents().find("#back-to-table").click(function(){
								$("#start-time").show();
								$("#end-time").show();
								$("#exam-search-btn").show();
								$("#rank-form-show").hide();
								$("#right-tables").show();
							});
							$("#start-time").hide();
							$("#end-time").hide();
							$("#exam-search-btn").hide();
							getExamRank(examcode,grades);
						});
						
					}else{
						content += "<div class=\"table-trs\">" +
										"<div class=\"no-data-show\">没有查到相关结果！</div>" +
									"</div>";
						$("#exam-data-show").empty();
						$("#exam-data-show").append(content);
						processEnd("加载成功");
					}
				}else{
					content += "<div class=\"table-trs\">" +
									"<div class=\"no-data-show\">没有查到相关结果！</div>" +
								"</div>";
					$("#exam-data-show").empty();
					$("#exam-data-show").append(content);
					processEnd("加载成功");
				}
			}else if(res.data == undefined || res.data == ""){
				content += "<div class=\"table-trs\">" +
								"<div class=\"no-data-show\">没有查到相关结果！</div>" +
							"</div>";
				$("#exam-data-show").empty();
				$("#exam-data-show").append(content);
				processEnd("加载成功");
			}else{
				content += "<div class=\"table-trs\">" +
								"<div class=\"no-data-show\">没有查到相关结果！</div>" +
							"</div>";
				$("#exam-data-show").empty();
				$("#exam-data-show").append(content);
				processError("加载失败");
			}
		},null,null);	
	}
	var ExamCode = "";
	var dataCache2 = [];
	//获得考试详情
	function getExamDetail(examname,examcode,grades){
		var list = [];
		var userKey = $("#user-name",parent.parent.parent.document).attr("key");
		var schoolcode = $("#user-name",parent.parent.parent.document).attr("schoolcode");
		var studentcode = $(".students-choice-select",parent.document).attr("studentcode");
		var data = {
				cmd:"getOneExamInfo",
				model:"bigexam",
				userKey:userKey,
				data:{
					examcode:examcode,
					grades:grades,
					type:1
				},
				remark:"",
				
		};
		processBegin("数据加载中······");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			var content = "";
			if(res.result == 1 && res.data != undefined && res.data != ""){
				var data = res.data;
				if(data.length > 0){
					dataCache = [];
					for(var i = 0; i < data.length; i++){
						for(var key in data[i]){
							if(data[i][key] == null || data[i][key] == "null" || data[i][key] == undefined){
								data[i][key] = "";
							}
						}
						content += "<div class=\"table-trs\">" +
							"<div class=\"tables-left\" style='margin-left:15px;width:120px;'>" +
								"<div class=\"table-name\" grades= \""+grades+"\" style='width:120px;' examcode=\""+data[i].examcode+"\" coursename=\""+data[i].coursename+"\" coursecode=\""+data[i].coursecode+"\" title='"+data[i].coursename+"'><a href='javascript:void(0)' class='into-exam-detail' coursecode = \""+data[i].coursecode+"\" coursename=\""+data[i].coursename+"\">"+data[i].coursename+ "</a></div>" +
								"<div class=\"table-code\" style='width:120px;'>"+data[i].remark+"</div>" +
							"</div>" +
							"<div class=\"tables-middle\" style='margin-left:25%;'>" +
								"<div class=\"table-code\" style='width:200px;'>开始时间:"+getFormatDateByLong(parseInt(data[i].stime)*1000,"yyyy-MM-dd hh:mm")+"</div>" +
								"<div class=\"table-code\" style='width:200px;'>结束时间:"+getFormatDateByLong(parseInt(data[i].etime)*1000,"yyyy-MM-dd hh:mm")+"</div>" +
							"</div>" +
							"<div class=\"tables-right\">" +
								"<div class=\"table-address\">满分值： "+data[i].score+"</div>" +
								"<div class=\"table-oprate\">" +
									"<div class=\"table-score\" grades= \""+grades+"\" style=\"margin-left:90px;\" dataindex = \""+i+"\" coursecode = \""+data[i].coursecode+"\" coursename=\""+data[i].coursename+"\" examcode=\""+data[i].examcode+"\" title=\"成绩\"></div>" +
								"</div>" +
							"</div>" +
						"</div>";
						dataCache.push(data[i]);
					}
					$("#detail-form-show").contents().find(".content-data-show").empty();
					$("#detail-form-show").contents().find(".content-data-show").append(content);
					processEnd("加载成功");
					$("#detail-form-show").contents().find(".table-trs").unbind("hover");
					$("#detail-form-show").contents().find(".table-trs").hover(function(){
						$(this).find(".table-oprate").show();
					},function(){
						$("#detail-form-show").contents().find(".table-oprate").hide();
					});
					//总榜-单科成绩
					$("#detail-form-show").contents().find(".table-score").unbind("click");
					$("#detail-form-show").contents().find(".table-score").click(function(){
						var coursename = $(this).attr("coursename");
						$("#score-form-show").show();
						$("#right-tables").hide();
						$("#score-form-show").contents().find(".table-title").text(examname + coursename + "成绩单");
						var coursecode = $(this).attr("coursecode");
						getSingleScore(examcode,coursecode,grades);
						$("#score-form-show").contents().find("#back-to-detail").unbind("click");
						$("#score-form-show").contents().find("#back-to-detail").click(function(){
							$("#score-form-show").hide();
							$("#right-tables").show();
						});
					});
					//总榜-科目名称-单科成绩
					$("#detail-form-show").contents().find(".into-exam-detail").unbind("click");
					$("#detail-form-show").contents().find(".into-exam-detail").click(function(){
						var coursename = $(this).attr("coursename");
						$("#score-form-show").show();
						$("#right-tables").hide();
						$("#score-form-show").contents().find(".table-title").text(examname + coursename + "成绩单");
						var coursecode = $(this).attr("coursecode");
						getSingleScore(examcode,coursecode,grades);
						$("#score-form-show").contents().find("#back-to-detail").unbind("click");
						$("#score-form-show").contents().find("#back-to-detail").click(function(){
							$("#score-form-show").hide();
							$("#right-tables").show();
						});
					});
				}else{
					content += "<div class=\"table-trs\">" +
									"<div class=\"no-data-show\">没有查到相关结果！</div>" +
								"</div>";
					$("#score-form-show").contents().find("#score-data-show").empty();
					$("#score-form-show").contents().find("#score-data-show").append(content);
					processEnd("加载成功");
				}
			}else{
				content += "<div class=\"table-trs\">" +
								"<div class=\"no-data-show\">没有查到相关结果！</div>" +
							"</div>";
				$("#score-form-show").contents().find("#score-data-show").empty();
				$("#score-form-show").contents().find("#score-data-show").append(content);
				processError("加载失败");
			}
		},null,null);
		return list;
	}
	//获得大考成绩单
	function getExamRank(examcode,grades){
		var list = [];
		var userKey = $("#user-name",parent.parent.parent.document).attr("key");
		var schoolcode = $("#user-name",parent.parent.parent.document).attr("schoolcode");	
		var studentcode = $(".students-choice-select",parent.document).attr("studentcode");
		var classcode = $(".students-choice-select",parent.document).attr("classcode");
		var data = {
				cmd:"getParentChildrenOneExamRank",
				model:"bigexam",
				userKey:userKey,
				data:{
					schoolcode:schoolcode,
					classcode:classcode,
					studentcode:studentcode,
					examcode:examcode,
					grades:grades,
					schooltype:1
				},
				remark:"",
				
		};
		processBegin("数据加载中······");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			var content = "";
			if(res.result == 1 && res.data != undefined && res.data != ""){
				var data = res.data;
				if(data.length > 0){
					content = "<table style='width:96%;margin-left:2%'><tr><td class='exam-left-title'>总分</td><td class='exam-left-content'>"+data[0].scorenumber+"</td><td class='exam-right-title'>校排</td><td class='exam-right-content'>第  "+data[0].schoolrank+" 名</td></tr>";
					var list = data[0].subjectinfo;
					var row = Math.ceil((list.length)/2);
					for(var i = 0;i < row;i ++){
						if(list[i*2+1] != "" && list[i*2+1] != undefined){
							content += "<tr><td class='exam-left-title'>"+list[i*2].subject+"</td><td class='exam-left-content'><input type='text' name='input-result' value='"+list[i*2].score+"' disabled='disabled'></td><td class='exam-right-title'>"+list[i*2+1].subject+"</td><td class='exam-right-content'><input type='text' name='input-result' value='"+list[i*2+1].score+"' disabled='disabled'></td></tr>";
						}else{
							content += "<tr><td class='exam-left-title'>"+list[i*2].subject+"</td><td class='exam-left-content'><input type='text' name='input-result' value='"+list[i*2].score+"' disabled='disabled'></td></tr>";
						}
					}
					content += "</table>";
					
					$("#rank-form-show").contents().find("#content-data-show").html(content);
					
					var cdsH =$("#rank-form-show").height() - $("#rank-form-show").contents().find(".content-title").height() - 40;
					$("#rank-form-show").contents().find(".content-data-show").height(cdsH);
					
					//导出成绩排名榜
					$("#rank-form-show").contents().find("#score-leading-out").unbind("click");
					$("#rank-form-show").contents().find("#score-leading-out").click(function(){
						exportRanking(examcode,grades);
					
					});
					processEnd("加载成功");
				}else{
					content += "<div class=\"table-trs\">" +
									"<div class=\"no-data-show\">没有查到相关结果！</div>" +
								"</div>";
					$("#rank-form-show").contents().find("#content-data-show").empty();
					$("#rank-form-show").contents().find("#content-data-show").append(content);
					processEnd("加载成功");
				}
			}else{
				content += "<div class=\"table-trs\">" +
								"<div class=\"no-data-show\">没有查到相关结果！</div>" +
							"</div>";
				$("#rank-form-show").contents().find("#content-data-show").empty();
				$("#rank-form-show").contents().find("#content-data-show").append(content);
				processError("加载失败");
			}
			
		},null,null);
		return list;
	}
	//获得单科成绩
	function getSingleScore(examcode,coursecode,grades){
		var list = [];
		var userKey = $("#user-name",parent.parent.parent.document).attr("key");
		var schoolcode = $("#user-name",parent.parent.parent.document).attr("schoolcode");	
		var studentcode = $(".students-choice-select",parent.document).attr("studentcode");
		var data = {
				cmd:"getParentChildrenOneEXamResult",
				model:"bigexam",
				userKey:userKey,
				data:{
					examcode:examcode,
					coursecode:coursecode,
					grades:grades,
					studentcode:studentcode,
					schoolcode:schoolcode,
					schooltype:1
				},
				remark:"",
				
		};
		processBegin("数据加载中······");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			var content = "";
			if(res.result == 1 && res.data != undefined && res.data != ""){
				var data = res.data;
				if(data.length > 0){
					dataCache = [];
					for(var i = 0; i < data.length; i++){
						for(var key in data[i]){
							if(data[i][key] == null || data[i][key] == "null" || data[i][key] == undefined){
								data[i][key] = "";
							}
						}
						content += "<div class=\"table-trs\">" +
							"<div class=\"tables-left\" style='margin-left:15px;width:120px;'>" +
								"<div class=\"table-name\" schooltype=\""+data[i].schooltype+"\" coursecode=\""+data[i].coursecode+"\" examcode=\""+data[i].examcode+"\" grades= \""+grades+"\" style='width:120px;' coursecontent='"+data[i].coursename+"' examcode=\""+data[i].examcode+"\" title='"+data[i].studentname+"'><a href='javascript:void(0)' class='studentname'>"+data[i].studentname + "</a></div>" +
								"<div class=\"table-code\" style='width:120px;'>"+data[i].studentcode+"</div>" +
							"</div>" +
							"<div class=\"tables-middle\" style='margin-left:25%;'>" +
								"<div class=\"table-class\" style='width:200px;'>分数： "+data[i].scorenumber+"</div>" +
								"<div class=\"table-code\" style='width:200px;'>"+data[i].grades+"年级"+data[i].classes+"班</div>" +
							"</div>" +
							"<div class=\"tables-right\">" +
								"<div class=\"table-address\">校排名： "+data[i].schoolrank+"</div>" +
								"<div class=\"table-address\">班内排名： "+data[i].classranking+"</div>" +
							"</div>" +
						"</div>";
						dataCache.push(data[i]);
					}
					$("#score-form-show").contents().find(".content-data-show").empty();
					$("#score-form-show").contents().find(".content-data-show").append(content);
					processEnd("加载成功");
					
					$("#score-form-show").contents().find("#leadingout-btn").unbind("click");
					$("#score-form-show").contents().find("#leadingout-btn").click(function(){
			 			leadingOutScore();
					});
				}else{
					content += "<div class=\"table-trs\">" +
									"<div class=\"no-data-show\">没有查到相关结果！</div>" +
								"</div>";
					$("#score-form-show").contents().find(".content-data-show").empty();
					$("#score-form-show").contents().find(".content-data-show").append(content);
					processEnd("加载成功");
				}
			}else if(res.data == undefined || res.data == ""){
				content += "<div class=\"table-trs\">" +
								"<div class=\"no-data-show\">没有查到相关结果！</div>" +
							"</div>";
				$("#score-form-show").contents().find(".content-data-show").empty();
				$("#score-form-show").contents().find(".content-data-show").append(content);
				processEnd("加载成功");
			}else{
				content += "<div class=\"table-trs\">" +
								"<div class=\"no-data-show\">没有查到相关结果！</div>" +
							"</div>";
				$("#score-form-show").contents().find(".content-data-show").empty();
				$("#score-form-show").contents().find(".content-data-show").append(content);
				processError("加载失败");
			}
//			callback(res.data);
		},null,null);
		return list;
	}
	function getExamResult(examcode){
		ExamCode = examcode;
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		var classcode = $("#student-class option:selected").val();
		var obj = {};
		obj.examcode = examcode;
		obj.schoolcode = schoolcode;
		if(classcode != ""){
			obj.classcode = classcode;
		}
		var data = {
				cmd:"getExamsresultAll",
				model:"teacher",
				userKey:userKey,
				data:obj,
				remark:"",						
		};
		processBegin("数据加载中······");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			var content = "";
			if(res.result == 1 && res.data != undefined && res.data != ""){
				var data = res.data;
				if(data.length > 0){
					dataCache2 = [];
					for(var i = 0; i < data.length; i++){
						for(var key in data[i]){
							if(data[i][key] == null || data[i][key] == "null" || data[i][key] == undefined){
								data[i][key] = "";
							}
						}
						content += "<div class=\"table-trs\">" +
							"<div class=\"tables-left\" style='margin-left:15px;width:120px;'>" +
								"<div class=\"table-name\" style='width:120px;' title='"+data[i].name+"'>"+substr(data[i].name,5) + "</div>" +
								"<div class=\"table-code\" style='width:120px;'>"+data[i].studentcode+"</div>" +
							"</div>" +
							"<div class=\"tables-middle\" style='margin-left:25%;'>" +
								"<div class=\"table-class\" style='width:200px;'>成绩： "+data[i].result+"</div>";
								if(data[i].grade != "" && data[i].classes != ""){
									content += "<div class=\"table-code\" style='width:200px;'>"+data[i].grade + "年级" + data[i].classes + "班" +"</div>";
								}else{
									content += "<div class=\"table-code\" style='width:200px;'>暂无</div>"; 
								}
								content += "</div>" +
							"<div class=\"tables-right\">" +
								"<div class=\"table-address\">第"+(i+1)+"名</div>" +
								"<div class=\"table-oprate\">" +
									"<div class=\"table-detail-exam\" dataindex = \""+i+"\" studentcode=\""+data[i].studentcode+"\" title=\"详情\"></div>" +
									"<div class=\"table-edit\" dataindex = \""+i+"\" studentcode=\""+data[i].studentcode+"\" title=\"编辑\"></div>" +
								"</div>" +
							"</div>" +
						"</div>";
						dataCache2.push(data[i]);
					}
					$("#result-form-show").contents().find("#result-data-show").empty();
					$("#result-form-show").contents().find("#result-data-show").append(content);
					processEnd("加载成功");
					
					var cdsH =$("#result-form-show").height() - $("#result-form-show").contents().find(".content-title").height() - 40;
					$("#result-form-show").contents().find(".content-data-show").height(cdsH);
					
					$("#result-form-show").contents().find(".table-trs").unbind("hover");
					$("#result-form-show").contents().find(".table-trs").hover(function(){
						$(this).find(".table-oprate").show();
					},function(){
						$("#result-form-show").contents().find(".table-oprate").hide();
					});
					
					$("#result-form-show").contents().find(".table-detail-exam").unbind("click");
					$("#result-form-show").contents().find(".table-detail-exam").click(function(){
						var index = parseInt($(this).attr("dataindex"));
						$("#resultform-form-show").show();
						$("#right-tables").hide();
						$("#resultform-form-show").contents().find("input").attr("disabled","disabled");
						$("#resultform-form-show").contents().find("input").css("background-color","#E5E5E5");
						$("#resultform-form-show").contents().find("select").attr("disabled","disabled");
						$("#resultform-form-show").contents().find("select").css("background-color","#E5E5E5");
						$("#resultform-form-show").contents().find("#back-to-table").unbind("click");
						$("#resultform-form-show").contents().find("#back-to-table").click(function(){
							$("#resultform-form-show").hide();
							$("#right-tables").show();
						});
						showData2(dataCache2[index],"detail");
					});
					
					$("#result-form-show").contents().find(".table-edit").unbind("click");
					$("#result-form-show").contents().find(".table-edit").click(function(){
						var index = parseInt($(this).attr("dataindex"));
						$("#resultform-form-show").show();
						$("#right-tables").hide();
						$("#resultform-form-show").contents().find("input").removeAttr("disabled");
						$("#resultform-form-show").contents().find("input").css("background-color","#fff");
						$("#resultform-form-show").contents().find("select").removeAttr("disabled");
						$("#resultform-form-show").contents().find("select").css("background-color","#fff");
						$("#resultform-form-show").contents().find("#back-to-table").unbind("click");
						$("#resultform-form-show").contents().find("#back-to-table").click(function(){
							$("#resultform-form-show").hide();
							$("#right-tables").show();
						});
						showData2(dataCache2[index],"edit");
						$("#resultform-form-show").contents().find("#save-btns").unbind("click");
						$("#resultform-form-show").contents().find("#save-btns").click(function(){
							updataResult();
						});
					});
					
					$("#result-form-show").contents().find(".table-delete").unbind("click");
					$("#result-form-show").contents().find(".table-delete").click(function(){
						var studentcode = $(this).attr("studentcode");
						deleteBox("确定要删除吗？",function(){
							deleteStudentRes(studentcode,ExamCode);
						});
					});
				}else{
					content += "<div class=\"table-trs\">" +
									"<div class=\"no-data-show\">没有查到相关结果！</div>" +
								"</div>";
					$("#result-form-show").contents().find("#result-data-show").empty();
					$("#result-form-show").contents().find("#result-data-show").append(content);
					processEnd("加载成功");
				}
			}else{
				content += "<div class=\"table-trs\">" +
								"<div class=\"no-data-show\">没有查到相关结果！</div>" +
							"</div>";
				$("#result-form-show").contents().find("#result-data-show").empty();
				$("#result-form-show").contents().find("#result-data-show").append(content);
				processError("加载失败");
			}
		},null,null);
	}
	function substr(str,len){
		if(str != undefined){
			if(str.length > len){
				str = str.substring(0,len-2)+"...";
				return str;
			}else{
				return str;
			}
		}else{
			return "";
		}
	}
	function showData(data,type){
		if(type == "detail"){
			$("#exam-form-show").contents().find("#save-btns-content").hide();
		}else if(type == "edit"){
			$("#exam-form-show").contents().find("#save-btns-content").show();
		}
		for(var key in data){
			if($("#exam-form-show").contents().find("#exam-" + key)[0]){
				if($("#exam-form-show").contents().find("#exam-" + key)[0].tagName.toLocaleLowerCase() == "input"){
					var time = "";
					if(key == "starttime" || key == "endtime" || key == "resulttime") {
						time = getFormatDateByLong(parseInt(data[key])*1000,"yyyy-MM-dd hh:mm");
						$("#exam-form-show").contents().find("#exam-" + key).val(time);
					}else{
						$("#exam-form-show").contents().find("#exam-" + key).val(data[key]);
					}
					
				}else if($("#exam-form-show").contents().find("#exam-" + key)[0].tagName.toLocaleLowerCase() == "select"){
					var len = $("#exam-form-show").contents().find("#exam-" + key+" option");
					for(var i = 0; i < len.length ; i++){
						if(len[i].value == data[key]){
							len[i].selected = true;
						}
					}
				}
			}
		}
	}
	function leadingOutScore(){
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		var studentcode = $(".students-choice-select",parent.document).attr("studentcode");
		var classcode = $(".students-choice-select",parent.document).attr("classcode");
		var examcode = $("#score-form-show").contents().find(".table-name").attr("examcode");
		var coursecode = $("#score-form-show").contents().find(".table-name").attr("coursecode");
		var schooltype = $("#score-form-show").contents().find(".table-name").attr("schooltype");
		var grades = $("#score-form-show").contents().find(".table-name").attr("grades");
		var filename = new Date().getTime();
		var t = Math.random();
		window.location = serverUrl.ExportUrl + "?t=" + t + "&cmd=getParentChildrenOneEXamResult" + "&examcode=" + examcode + "&schoolcode=" + schoolcode + "&classcode=" + classcode + "&coursecode=" + coursecode + "&grades=" + grades + "&studentcode=" + studentcode + "&schooltype=" + schooltype + "&fileName=" + filename;
	}
	function showData2(data,type){
		if(type == "detail"){
			$("#resultform-form-show").contents().find("#save-btns-content").hide();
		}else if(type == "edit"){
			$("#resultform-form-show").contents().find("#save-btns-content").show();
		}
		for(var key in data){
			if($("#resultform-form-show").contents().find("#exam-" + key)[0]){
				if($("#resultform-form-show").contents().find("#exam-" + key)[0].tagName.toLocaleLowerCase() == "input"){
					$("#resultform-form-show").contents().find("#exam-" + key).val(data[key]);
				}else if($("#resultform-form-show").contents().find("#exam-" + key)[0].tagName.toLocaleLowerCase() == "select"){
					var len = $("#resultform-form-show").contents().find("#exam-" + key+" option");
					for(var i = 0; i < len.length ; i++){
						if(len[i].value == data[key]){
							len[i].selected = true;
						}
					}
				}
			}
		}
	}
	function exportRanking(examcode,grades){
		var classcode = $(".students-choice-select",parent.document).attr("classcode");
		var studentcode = $(".students-choice-select",parent.document).attr("studentcode");
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		window.frames["export"].location = serverUrl.ExportUrl + "?t=" + Math.random() + "&cmd=getParentChildrenOneExamRank" + "&examcode=" + examcode + "&schoolcode=" + schoolcode + "&classcode=" + classcode + "&studentcode=" + studentcode + "&grades=" + grades + "&fileName=" + new Date().getTime();
	}
	function pagebtns(){
		$("#exam-search-btn").click(function(){
			now = 0;
			initExam(1,pageSize);
		});
		$(".students-choice",parent.document).unbind("click");
		$(".students-choice",parent.document).click(function(){
			$(".students-choice",parent.document).removeClass("classes-choice-select");
			$(this).addClass("students-choice-select");
			now = 0;
			initExam(1,pageSize);
			
		});	
		
	}
	function initSmPages(){
		var rcH = $(".body-right",parent.document).height() - $(".right-title").height()-3;
		$(".right-content").height(rcH);
		
		var cdsH = $(".right-content").height() - $(".content-title").height() - 40;
		$(".content-data-show").height(cdsH);
	}
})();